package org.niu.str;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class FindRepeatedDnaSequences {
    public List<String> findRepeatedDnaSequences(String s) {
        Map<String,Integer> mp = new HashMap<>();
        List<String> ans = new ArrayList<>();
        if(s.length()<10){
            return ans;
        }
        for (int i = 0; i < s.length()-10; i++) {
            mp.put(s.substring(i,i+10),mp.getOrDefault(s.substring(i,i+10),0)+1);
        }
        for(Map.Entry<String,Integer> entry:mp.entrySet()){
            if(entry.getValue()>1){
                ans.add(entry.getKey());
            }
        }
        return ans;
    }
}
